namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_cart 的摘要说明
/// </summary>
public class t_cart:IEntityUtil
{
//   购物车号值的哈希表 
	private static Hashtable m_enum_cartID;
	public static Hashtable  enum_cartID
	{
		get{return m_enum_cartID;}
	}
	public const String guid="cartID";
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Cart __cart;
	public String id  
	{
		get{return __cart.id;}
		set{ __cart.id=value;}
	}
	public String cartID  
	{
		get{return __cart.cartID;}
		set{ __cart.cartID=value;}
	}
	public long commoditySeqID  
	{
		get{return __cart.commoditySeqID;}
		set{ __cart.commoditySeqID=value;}
	}
	public double salePrice  
	{
		get{return __cart.salePrice;}
		set{ __cart.salePrice=value;}
	}
	public double saleAmount  
	{
		get{return __cart.saleAmount;}
		set{ __cart.saleAmount=value;}
	}
	public DateTime saleTime  
	{
		get{return __cart.saleTime;}
		set{ __cart.saleTime=value;}
	}
	private static  CartDao dao=(CartDao)SpringContext.Context.GetObject("CartDao");
	public static CartDao DAO
	{
		get{return dao;}
		
	}
	
	public t_cart()
	{
		__cart=new Cart();
	  	id="";
	  	cartID="";
	  	commoditySeqID=consts.long_min;
	  	salePrice=consts.double_min;
	  	saleAmount=consts.double_min;
	  	saleTime=DateTime.Now;
	  // dao=(CartDao)SpringContext.Context.GetObject("CartDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"表主键");
		colNames.Add("id");
		m_colLabels.Add("cartID", @"购物车号");
		colNames.Add("cartID");
		m_enum_cartID= new Hashtable();
		m_enum_cartID.Add("cartID", @"购物车号");
		m_colLabels.Add("commoditySeqID", @"商品主键");
		colNames.Add("commoditySeqID");
		m_colLabels.Add("salePrice", @"单价");
		colNames.Add("salePrice");
		m_colLabels.Add("saleAmount", @"数量");
		colNames.Add("saleAmount");
		m_colLabels.Add("saleTime", @"销售时间");
		colNames.Add("saleTime");
	  }
	
	}
	public t_cart(Cart entity )
	{
		__cart=entity;
		
	  // dao=(CartDao)SpringContext.Context.GetObject("CartDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"表主键");
		colNames.Add("id");
		m_colLabels.Add("cartID", @"购物车号");
		colNames.Add("cartID");
		m_enum_cartID= new Hashtable();
		m_enum_cartID.Add("cartID", @"购物车号");
		m_colLabels.Add("commoditySeqID", @"商品主键");
		colNames.Add("commoditySeqID");
		m_colLabels.Add("salePrice", @"单价");
		colNames.Add("salePrice");
		m_colLabels.Add("saleAmount", @"数量");
		colNames.Add("saleAmount");
		m_colLabels.Add("saleTime", @"销售时间");
		colNames.Add("saleTime");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Cart));}
     }
	public const string ENTITYNAME="t_cart";
	public const int SEQN0=180;
	
    public void checkAdd()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("表主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("表主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("表主键是主健，框架要求值不能为0"));				

	
	if((cartID!=guid))
		throw (new Exception("购物车号值不在要求范围内"));			

	//try{Convert.ToInt64(commoditySeqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	commoditySeqID<consts.long_min+1)
			throw (new Exception("请输入商品主键"));

	//try{Convert.ToDouble(salePrice);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	salePrice<consts.double_min+1)
			throw (new Exception("请输入单价"));
		if(salePrice>0)
			salePrice+=0.000001;
		if(salePrice<0)
			salePrice-=0.000001;
		
			if(((long)((salePrice)*100 ))*10!=(long)((salePrice)*1000) )
				throw (new Exception("单价小数精度不能大于2位salePrice="+salePrice.ToString()));
		if(salePrice>0)
			salePrice-=0.000001;
		if(salePrice<0)
			salePrice+=0.000001;
	

	//try{Convert.ToDouble(saleAmount);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	saleAmount<consts.double_min+1)
			throw (new Exception("请输入数量"));
		if(saleAmount>0)
			saleAmount+=0.000001;
		if(saleAmount<0)
			saleAmount-=0.000001;
		
			if(((long)((saleAmount)*100 ))*10!=(long)((saleAmount)*1000) )
				throw (new Exception("数量小数精度不能大于2位saleAmount="+saleAmount.ToString()));
		if(saleAmount>0)
			saleAmount-=0.000001;
		if(saleAmount<0)
			saleAmount+=0.000001;
	

	//try{Convert.ToDateTime(saleTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	saleTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入销售时间"));

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	
	len=id.Trim().Length;
	if(len>32)
		 throw (new Exception("表主键字符长度最长不能超过32,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("表主键不能为空!"));	
	
 if(id=="0")
	 throw (new Exception("表主键是主健，框架要求值不能为0"));				

	
	if((cartID!=guid))
		throw (new Exception("购物车号值不在要求范围内"));			

	//try{Convert.ToInt64(commoditySeqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	commoditySeqID<consts.long_min+1)
			throw (new Exception("请输入商品主键"));

	//try{Convert.ToDouble(salePrice);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	salePrice<consts.double_min+1)
			throw (new Exception("请输入单价"));
		if(salePrice>0)
			salePrice+=0.000001;
		if(salePrice<0)
			salePrice-=0.000001;
		
			if(((long)((salePrice)*100 ))*10!=(long)((salePrice)*1000) )
				throw (new Exception("单价小数精度不能大于2位salePrice="+salePrice.ToString()));
		if(salePrice>0)
			salePrice-=0.000001;
		if(salePrice<0)
			salePrice+=0.000001;
	

	//try{Convert.ToDouble(saleAmount);}catch{ throw (new Exception("请输入正确的小数格式"));		}
		if(	saleAmount<consts.double_min+1)
			throw (new Exception("请输入数量"));
		if(saleAmount>0)
			saleAmount+=0.000001;
		if(saleAmount<0)
			saleAmount-=0.000001;
		
			if(((long)((saleAmount)*100 ))*10!=(long)((saleAmount)*1000) )
				throw (new Exception("数量小数精度不能大于2位saleAmount="+saleAmount.ToString()));
		if(saleAmount>0)
			saleAmount-=0.000001;
		if(saleAmount<0)
			saleAmount+=0.000001;
	

	//try{Convert.ToDateTime(saleTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	saleTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入销售时间"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("id", id);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__cart);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByid()
    {
    
        try
        {
          dao.Delete(__cart);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__cart);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,id);	
m_updateRow(rowNo,ii++,/***/(						string.Format("{0:F2}",salePrice)/***/)
);	
m_updateRow(rowNo,ii++,/***/(						string.Format("{0:F2}",saleAmount)/***/)
);	
m_updateRow(rowNo,ii++,			saleTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)saleTime).Hour + ((DateTime)saleTime).Minute==0?string.Format("{0:d}",saleTime):string.Format("{0:G}",saleTime));	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"表主键");
			m_insertHead(ii++,100,"单价");
			m_insertHead(ii++,100,"数量");
			m_insertHead(ii++,100,"销售时间");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,id);
     	m_insertRow(0,ii++,/***/(						string.Format("{0:F2}",salePrice)/***/)
);
     	m_insertRow(0,ii++,/***/(						string.Format("{0:F2}",saleAmount)/***/)
);
     	m_insertRow(0,ii++,			saleTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)saleTime).Hour + ((DateTime)saleTime).Minute==0?string.Format("{0:d}",saleTime):string.Format("{0:G}",saleTime));
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"表主键");
			m_insertHead(ii++,100,"单价");
			m_insertHead(ii++,100,"数量");
			m_insertHead(ii++,100,"销售时间");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Cart obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,obj.id.ToString());
m_insertRow(j,ii++,(					string.Format("{0:F2}",obj.salePrice)
					)
);
m_insertRow(j,ii++,(					string.Format("{0:F2}",obj.saleAmount)
					)
);
m_insertRow(j,ii++,			obj.saleTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)obj.saleTime).Hour + ((DateTime)obj.saleTime).Minute==0?string.Format("{0:d}",obj.saleTime):string.Format("{0:G}",obj.saleTime)
);
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Cart obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__cart=obj;
            	return true;
            }
        
    }
    public static t_cart Get(DetachedCriteria dc)
    {
    	
    	Cart obj=((CartDao)SpringContext.Context.GetObject("CartDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_cart( obj );
        
    }
	 public static t_cart GetById(String val)
	 {
	 	Cart obj=((CartDao)SpringContext.Context.GetObject("CartDao"))
	 	.GetById(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_cart( obj );
	 	
	 	
	 }
	 public  bool InitById(String val)
	 {
	 	

	 	Cart obj=dao.GetById(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__cart=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			Controls["id"].Text=id;
		}
		if(Controls["cartID"]!=null)
		{
			Controls["cartID"].Text=	t_cart.enum_cartID[cartID.ToString()].ToString()
;
		}
		if(Controls["commoditySeqID"]!=null)
		{
			Controls["commoditySeqID"].Text=				(				  string.Format("{0}",commoditySeqID)				  );
		}
		if(Controls["salePrice"]!=null)
		{
			Controls["salePrice"].Text=/***/(						string.Format("{0:F2}",salePrice)/***/)
;
		}
		if(Controls["saleAmount"]!=null)
		{
			Controls["saleAmount"].Text=/***/(						string.Format("{0:F2}",saleAmount)/***/)
;
		}
		if(Controls["saleTime"]!=null)
		{
			Controls["saleTime"].Text=			saleTime.ToString().CompareTo("1001-1-1")<0?"":((DateTime)saleTime).Hour + ((DateTime)saleTime).Minute==0?string.Format("{0:d}",saleTime):string.Format("{0:G}",saleTime);
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_cart Init(Cart item)
    {
        __cart=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			
			if(Controls["id"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["id"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{id=v;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("表主键格式不正确！！"));
				}
				
			}
			else
			{
				try{id=Controls["id"].Text;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("表主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["cartID"]!=null)
		{
			
			if(Controls["cartID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["cartID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{cartID=v;}
				catch
				{
					 Controls["cartID"].Focus();
					throw  (new Exception("购物车号格式不正确！！"));
				}
				
			}
			else
			{
				try{cartID=Controls["cartID"].Text;}
				catch
				{
					 Controls["cartID"].Focus();
					throw  (new Exception("购物车号格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["commoditySeqID"]!=null)
		{
			
			if(Controls["commoditySeqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["commoditySeqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{commoditySeqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["commoditySeqID"].Focus();
					throw  (new Exception("商品主键格式不正确！！"));
				}
				
			}
			else
			{
				try{commoditySeqID=(Controls["commoditySeqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["commoditySeqID"].Text));}
				catch
				{
					 Controls["commoditySeqID"].Focus();
					throw  (new Exception("商品主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["salePrice"]!=null)
		{
			
			if(Controls["salePrice"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["salePrice"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{salePrice=(v==""?consts.double_min:Convert.ToDouble(v));}
				catch
				{
					 Controls["salePrice"].Focus();
					throw  (new Exception("单价格式不正确！！"));
				}
				
			}
			else
			{
				try{salePrice=(Controls["salePrice"].Text==""?consts.double_min:Convert.ToDouble(Controls["salePrice"].Text));}
				catch
				{
					 Controls["salePrice"].Focus();
					throw  (new Exception("单价格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["saleAmount"]!=null)
		{
			
			if(Controls["saleAmount"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["saleAmount"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{saleAmount=(v==""?consts.double_min:Convert.ToDouble(v));}
				catch
				{
					 Controls["saleAmount"].Focus();
					throw  (new Exception("数量格式不正确！！"));
				}
				
			}
			else
			{
				try{saleAmount=(Controls["saleAmount"].Text==""?consts.double_min:Convert.ToDouble(Controls["saleAmount"].Text));}
				catch
				{
					 Controls["saleAmount"].Focus();
					throw  (new Exception("数量格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["saleTime"]!=null)
		{
			
			if(Controls["saleTime"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["saleTime"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{saleTime=(v==""?new DateTime(1000,1,1):Convert.ToDateTime(v));}
				catch
				{
					 Controls["saleTime"].Focus();
					throw  (new Exception("销售时间格式不正确！！"));
				}
				
			}
			else
			{
				try{saleTime=(Controls["saleTime"].Text==""?new DateTime(1000,1,1):Convert.ToDateTime(Controls["saleTime"].Text));}
				catch
				{
					 Controls["saleTime"].Focus();
					throw  (new Exception("销售时间格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
